<template>
  <view>
    <view class="UgobackFix" @tap="backFn">
      <view class="i ico"></view>
    </view>
    <block v-if="ifps == 1">
      <view style="margin-top: 200rpx">需要您本人亲自到店</view>
      <view style="padding: 100rpx">与经纪人面谈沟通，工作人员人工帮您点亮，或扫码预约客服，安排经纪人上门与您面谈。</view>
    </block>
    <block v-else>
      <button v-if="btn5startflag" :style="'--color:' + color + ';--rgbcolor:' + rgbcolor" class="btn5"
              @tap="startRecord">开始
      </button>
      <camera class="camera" devicePosition="front" flash="off" frameSize="small" resolution="low" @error="errorFn"
              @stop="errorFn"></camera>
      <image :src="WWW + '/res/m/img/facebg.png?' + cache_str" class="facebg" mode="widthFix"></image>
      <view v-if="tips3flag" class="tips3">
        <view>
          <image :src="WWW + '/res/m/img/face_tips1.png?' + cache_str"></image>
          <text>不能佩戴眼镜</text>
        </view>
        <view>
          <image :src="WWW + '/res/m/img/face_tips2.png?' + cache_str"></image>
          <text>摘口罩露额头</text>
        </view>
        <view>
          <image :src="WWW + '/res/m/img/face_tips3.png?' + cache_str"></image>
          <text>放慢摇头等动作</text>
        </view>
      </view>
      <view v-if="cartoonflag" class="cartoon">
        <image :src="WWW + '/res/m/img/face.gif?' + cache_str" mode="aspectFill"></image>
      </view>
    </block>
  </view>
</template>

<script>
var t;
var a = require('../../res/www.a9a.cn.js');
var app = getApp();
export default {
  data() {
    return {
      vobj: '',
      light_old: '',
      color: '',
      miao: 8,
      btn5startflag: true,
      tips3flag: true,
      cartoonflag: false,
      ifps: '',
      rgbcolor: '',
      siteName: '',
      WWW: '',
      cache_str: '',
      truename: '',
      identitynum: '',
      src: '',
      videoSrc: ''
    };
  },
  onLoad: function (t) {
    var that = this;
    var n = t.truename;
    var i = t.identitynum;
    app.globalData.chklogin().then(function (t) {
      t || uni.navigateBack();
    });
    app.globalData.ajax({
      url: 'get_config.php',
      data: {
        f: '_ZEAI',
        ver: 10
      },
      success: function (t) {
        uni.setStorageSync('COOK_ZEAI', {
          ifps: t.ifps,
          siteName: t.siteName,
          color: t.color,
          loveb: t.loveb,
          cache_str: t.cache_str,
          tabbar: t.tabbar
        });
        that.setData({
          ifps: t.ifps,
          color: t.color,
          rgbcolor: a.c16_rgb(t.color),
          siteName: t.siteName,
          WWW: app.globalData.WWW,
          cache_str: t.cache_str,
          truename: n,
          identitynum: i
        });
      }
    });
    this.vobj = uni.createCameraContext();
    uni.getScreenBrightness({
      success: function (t) {
        that.setData({
          light_old: t.value
        });
        setTimeout(function () {
          uni.setScreenBrightness({
            value: 0.8
          });
        }, 1000);
      }
    });
    (!a.empty(n) && a.ifsfz(i)) ||
    uni.showModal({
      content: '姓名或身份证号不能为空',
      confirmColor: that.color,
      confirmText: '朕知道了',
      showCancel: false,
      success: function (t) {
        uni.navigateBack();
      }
    });
  },
  onHide: function () {
    uni.setScreenBrightness({
      value: this.light_old
    });
  },
  onUnload: function () {
    uni.setScreenBrightness({
      value: this.light_old
    });
  },
  methods: {
    backFn: function () {
      uni.navigateBack();
      uni.setScreenBrightness({
        value: this.light_old
      });
    },

    startRecord: function () {
      var that = this;
      this.vobj.startRecord({
        success: function (t) {
          console.log('startRecord');
        }
      });
      that.setData({
        btn5startflag: false,
        tips3flag: false,
        cartoonflag: true
      });
      that.time = setInterval(function () {
        that.setData({
          miao: that.miao - 1
        });
        if (0 == that.miao) {
          clearInterval(that.time);
          that.stopRecord();
        }
      }, 1000);
    },

    stopRecord: function () {
      var that = this;
      var n = this;
      this.vobj.stopRecord({
        success: function (i) {
          console.log('这是什么视频数据', i)
          that.setData({
            src: i.tempThumbPath,
            videoSrc: i.tempVideoPath
          });
          uni.showLoading({
            title: '正在活体检测...'
          });
          t = uni.getStorageSync('COOK_U');
          var s = {
            submitok: 'face_update',
            truename: n.truename,
            identitynum: n.identitynum,
            openid: t.openid
          };
          console.log('这是上传视频===', n.videoSrc)
          console.log('这是s是一些什么东西', s)
          uni.uploadFile({
            url: app.globalData.WWW + '/api/wxxcx/my_cert.php',
            filePath: n.videoSrc,
            name: 'video',
            formData: s,
            success: function (t) {
              console.log('这是上传视频返回的什么', t)
              t = a.jsoneval(t.data);
              uni.hideLoading();
              uni.showLoading({
                title: '正在进行公安库验证中...'
              });
              if (1 == t.flag) {
                console.log('然后有没有进入这个上传n.src', n.src)
                console.log('这里的又是什么', s)
                uni.uploadFile({
                  url: app.globalData.WWW + '/api/wxxcx/my_cert.php',
                  filePath: n.src,
                  name: 'pic',
                  formData: s,
                  success: function (t) {
                    console.log('判断结果', t)
                    uni.hideLoading();
                    if (1 == (t = a.jsoneval(t.data)).flag) {
                      uni.showToast({
                        title: t.msg,
                        mask: true,
                        duration: 3000
                      });
                      setTimeout(function () {
                        uni.navigateBack({
                          delta: 2
                        });
                      }, 3000);
                    } else {
                      uni.showModal({
                        content: t.msg,
                        confirmColor: n.color,
                        confirmText: '朕知道了',
                        showCancel: false,
                        success: function (t) {
                          uni.navigateBack();
                        }
                      });
                    }
                  }
                });
              } else {
                uni.showModal({
                  content: t.msg,
                  confirmColor: n.color,
                  confirmText: '朕知道了',
                  showCancel: false,
                  success: function (t) {
                    uni.navigateBack();
                  }
                });
              }
            }
          });
        }
      });
    },

    errorFn: function () {
      uni.navigateBack();
      uni.setScreenBrightness({
        value: this.light_old
      });
    }
  }
};
</script>
<style>
@import 'cert_face.css';
</style>
